import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://localhost:3000'
})

instance.interceptors.response.use(
  config => {
    // if (response.status === 200 && response.data.code === 200) {
    //   return response.data
    // }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)

instance.interceptors.response.use(res => {
  return res.data;
}, err => {
  if (err && err.response) {
    switch (err.response.status) {
      case 400:
        console.log("请求错误");
        break;
      case 401:
        console.log("未授权访问");
        break;
      default:
        console.log("其他错误信息");
    }
  }
  return err;
});


export default instance
